package com.yunhe.tianhe.rentcars.controller.cheliangguanli;


import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.entity.cheliangguanli.WeiXiu;
import com.yunhe.tianhe.rentcars.entity.cheliangguanli.XinXi;
import com.yunhe.tianhe.rentcars.entity.cheliangguanli.ZiYong;
import com.yunhe.tianhe.rentcars.service.cheliangguanli.XinXiService;
import com.yunhe.tianhe.rentcars.service.cheliangguanli.ZiYongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/ziyong")
public class ZiYongController {
    @Autowired
    private ZiYongService ziYongService;
    @Autowired
    private XinXiService xinXiService;


    @RequestMapping("/list")
    public String list(){
        return "cheliangguanli/ziyong/ziyonglist";
    }

    @ResponseBody
    @RequestMapping("/listData")
    public Pageable<WeiXiu> listdata(Integer offset, Integer limit, String carcode, @DateTimeFormat(pattern = "yyyy-MM-dd") Date usecartime, @DateTimeFormat(pattern = "yyyy-MM-dd") Date returntime){
        Pageable page = ziYongService.findPage(offset, limit,carcode,usecartime,returntime);
        return page;
    }

    @RequestMapping("/add")
    public String add(HttpServletRequest req){
        List<XinXi> list = xinXiService.findAll();
        req.getSession().setAttribute("aa",list);
        return "cheliangguanli/ziyong/ziyongadd";
    }

    @RequestMapping("/save")
    public String save(ZiYong ziYong){
        ziYongService.save(ziYong);
        return "cheliangguanli/ziyong/ziyonglist";
    }
}
